﻿using System;

namespace Teal.Compiler {

    /// <summary>
    /// 表示一个版本号。
    /// </summary>
    public struct Version {

        /// <summary>
        /// 获取主版本号。
        /// </summary>
        public byte majorVersion;

        /// <summary>
        /// 获取次版本号。
        /// </summary>
        public byte minorVersion;

        /// <summary>
        /// 获取修订版本号。
        /// </summary>
        public byte revisionVersion;

        /// <summary>
        /// 获取编译版本号。
        /// </summary>
        public byte buildVersion;

        public static explicit operator Version(int value) {
            return new Version() { majorVersion = (byte)value };
        }

        public static explicit operator Version(double value) {
            return new Version() { majorVersion = (byte)Math.Floor(value), minorVersion = (byte)((short)Math.Floor(value * 100) / 100) };
        }

        public override string ToString() {
            return String.Format("{0}.{1}.{2}.{3}", majorVersion, minorVersion, revisionVersion, buildVersion);
        }

    }

}